<template>
  <div>

    <a-form :label-col="{ span: 6 }"
            :wrapper-col="{ span: 16 }"
            :form="form">

          <a-form-item label="秒杀订单超过：">
        <div style="display:flex;margin-top:5px;">
          <a-input :maxLength="10" :disabled="isUpdata" addon-after="分"
                   v-decorator="[ 'secondsKillOrder', { rules: [
                      { required: true, message: '表单不能为空' },
                      { validator: validateIsNumber}
                    ] }]" />
          <p class="lable">未付款，订单自动关闭</p>
        </div>

      </a-form-item>
      <a-form-item label="正常订单超过：">
        <div style="display:flex;margin-top:5px;">
          <a-input :maxLength="10" :disabled="isUpdata" addon-after="分"
                   v-decorator="[ 'goodsOrderEndTime', { rules: [{ required: true, message: '表单不能为空' },
                    { validator: validateIsNumber}] },]" />
          <p class="lable">未付款，订单自动关闭</p>
        </div>

      </a-form-item>
      <a-form-item label="发货超过：">
        <div style="display:flex;margin-top:5px;">
          <a-input :maxLength="10" :disabled="isUpdata" addon-after="天"
                   v-decorator="[ 'goodsOrderFinishTime', { rules: [{ required: true, message: '表单不能为空' },
                   { validator: validateIsNumber}] },]" />
          <p class="lable">未收货，订单自动完成</p>
        </div>

      </a-form-item>
      <a-form-item label=" 申请退款超过：">
        <div style="display:flex;margin-top:5px;">
          <a-input :maxLength="10" :disabled="isUpdata" addon-after="天"
                   v-decorator="[ 'automaticRefund', { rules: [{ required: true, message: '表单不能为空' },
                   { validator: validateIsNumber}] },]" />
          <p class="lable">多少天没有审核，自动退款</p>
        </div>

      </a-form-item>
      <a-form-item label=" 订单完成超过：">
        <div style="display:flex;margin-top:5px;">
          <a-input :maxLength="10" :disabled="isUpdata" addon-after="天"
                   v-decorator="[ 'goodsOrderFavorableTime', { rules: [{ required: true, message: '表单不能为空' },
                   { validator: validateIsNumber}] },]" />
          <p class="lable">自动五星好评</p>
        </div>

      </a-form-item>
      <a-form-item label="退货时间超时：">
        <div style="display:flex;margin-top:5px;">
          <a-input :maxLength="10" :disabled="isUpdata" addon-after="天"
                   v-decorator="[ 'cancelRefund', { rules: [{ required: true, message: '表单不能为空' },
                   { validator: validateIsNumber}] },]" />
          <p class="lable">审核通过后多少天未寄回商品，自动取消退货</p>
        </div>

      </a-form-item>
    </a-form>
    <div class="footerBtn">
      <a-button type="primary" v-if="isUpdata" @click="isUpdata=!isUpdata"> 修改 </a-button>
      <a-button class="twoBtn" v-if="!isUpdata" @click="isUpdata=!isUpdata"> 取消 </a-button>
      <a-button type="primary" v-if="!isUpdata" @click="handleOk"> 保存 </a-button>
    </div>
  </div>
</template>
<script>
export default {
  data() {
    return {
      form: this.$form.createForm(this, { name: "coordinated" }),
      isUpdata:true,
      records:{},
    };
  },
  created(){
    this.getOrderInfo();
  },
  methods: {
    validateIsNumber(rule, value, callback) {
      if (value.indexOf('.')!=-1) {
        callback(new Error("请输入整数"));
        return;
      }
      callback();
    },
    async getOrderInfo(){
      let res = await this.$get('/order/config/query');
      if(res && res.returnCode=='1000'){
        this.records=res.dataInfo || {};
        this.setFieldsValue();
      }
    },
    setFieldsValue(){
      this.$nextTick(() => {
        const formItems = this.form.getFieldsValue();
        Object.keys(formItems).forEach((key) => {
          formItems[key] = this.records[key];
        });
        this.form.setFieldsValue(formItems);
      });
    },
    handleOk(e) {
      this.form.validateFields((err, values) => {
        if (!err) {
          let url = `/order/config/update`;
          this.$post(url, { ...values,id:this.records.id }).then((res) => {
            if (res && res.returnCode === 1000) {
              this.$message.success("保存成功！");
              //this.$emit("handleSubmit");
              this.isUpdata=!this.isUpdata
            }
          });
        }
      });
    },
  },
};
</script>
<style rel='stylesheet/less' lang='less' scoped>
//@import url();
.lable {
  width: 500px;
  line-height: 30px;
  margin-left: 10px;
}
.footerBtn {
  margin-top: 100px;
  display: flex;
  justify-content: center;
  .twoBtn {
    margin: 0 20px;
  }
}
</style>
